package pl.edu.agh.jemo.evolution.selections;

import javax.swing.JPanel;

import pl.edu.agh.jemo.evolution.population.Population;
import pl.edu.agh.jemo.gui.panels.selection.TournamentConfigPanel;
/**
 * Root class for all selection implementations.
 * Implementing class should define how to filter weaker specimen from population.
 * Every Tournament implementation must ensure, that result population doesn't contain the same specimen reference twice, as it might result with strange behaviour of algorithm in next steps.
 *  
 * @author Marcin Zbijowski
 *
 */
public abstract class Tournament {

	/**
	 * Number of specimen expected to be in population after tournament. This number shouldn't be graeter then input population size.
	 */
	protected int expectedPopulationSize = 400;
	
	/**
	 * Performs tournament by selecting stronger specimen in implementators defined way.
	 * 
	 * @param competitors Population reference for which tournament should be performed. The same instnce contains result population after method call. 
	 */
	public abstract void performTournament(Population competitors);

	/**
	 * Returns expected number of specimen in population after tournament.
	 * 
	 * @return Value of expected population size parameter.
	 */
	public int getExpectedPopulationSize() {
		return expectedPopulationSize;
	}

	/**
	 * Sets number of specimen expected to be in population after tournament.
	 * 
	 * @param expectedPopulationSize New number of expected specimen count in population.
	 */
	public void setExpectedPopulationSize(int expectedPopulationSize) {
		this.expectedPopulationSize = expectedPopulationSize;
	}

	/**
	 * Returns configuration panel being extension of JPanel instance.
	 * Returned panel is displayed by graphical user interface allowing user to confgiure tournament.
	 * This method may return null if no configuration for operator is possible.
	 * 
	 * @return Instance of JPanel with initialized components prepared to configure tournament properties.
	 */
	public JPanel getConfigPanel() {
		return new TournamentConfigPanel(this);
	}

	/**
	 * Returns String object containing description of tournament configuration in readable form as a summary.
	 * 
	 * @return String description of tournament configuration.
	 */
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("Torunament class: " + getClass().getSimpleName() + "\n");
		return sb.toString();
	}
}
